const app = getApp()
const util = require("../../../util/util.js")

Page({
  data: {
    loading: 1,
    isSuddenSupervising: false,
  },
  onLoad: function (options) {
    this.setData({
      loading: 0,
      isSuddenSupervising: app.globalData.isSuddenSupervising
    })
  },



  confirmSuddenSupervise: function (e) {
      dd.navigateTo({
        url: `/subpages/pages/schoolSelect/schoolSelect?type=2`,
      })
  },

  endSuddenSupervise: function (e) {
    console.log("app", app.globalData)
    dd.confirm({
      title: '提示',
      content: '确定结束当前日常巡查？',
      success: function (res) {
        if (res.confirm) {
          const userId = app.globalData.userId
          dd.httpRequest({
            url: app.baseUrl + '/DingDing/Supervise/endSuddenSupervise',
            method: "POST",
            headers: {
              "Content-Type": "application/json"
            },
            data: JSON.stringify({
              userId: userId,
            }),
            dataType: 'text',
            success: res => {
              if (res.data == "success") {
                app.globalData.isSuddenSupervising = false
                app.globalData.superviseSchoolId = 0
                app.globalData.superviseSchoolName = ""
                dd.showToast({
                  content: '当前日常巡查已结束!'
                })
                setTimeout(() => {
                  dd.redirectTo({
                    url: `/subpages/pages/suddensupervise/suddensupervise`,
                  })
                }, 1000)
              }
            }
          })
        } else if (res.cancel) {
          console.log("取消")
        }
      }
    })
  }
})